package com.jt.controller;/**
 * @Author 金帮嘉诚 @Date 2021-07-26 星期一 11:08
 */
/*本类用于测试*/

import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 知识点
 */

@RestController
//协议、域名、端口号
//(origins = "http://127.0.0.1:8848")//这里要用8848端口才可以访问，不能8090
@CrossOrigin(origins = "http://127.0.0.1:8848")
@RequestMapping("/")
public class UserController {
    @Autowired
    private UserService userService;

    //这是一个测试 测试servlet解析传递的数据串
//    @GetMapping("gA")
//    public User getAll(HttpServletRequest request, HttpServletResponse response) {
//        String id0 = request.getParameter("id");
//        Integer id = Integer.valueOf(id0);
//        User user = new User();
//        user.setId(id);
//        return user;
//
//    }

    @GetMapping("getAll")
    public List<User> getAll() {
        return userService.getALl();
    }

    @DeleteMapping("delete")
    public int delete(Integer id) {
        return userService.delete(id);
    }
    @PutMapping("update")
    public int update(User user){
        return userService.update(user);
    }
    @PostMapping("add")
    public int add(User user){
        return userService.add(user);
    }

}
